<template>
  <div class="dashboard-container">
    <common-view
      :table-prop="tableProp"
      :form-rules="formRules"
      module-name="sceneList"
      :search="getSceneList"
      :add="addScene"
      :delete="deleteScene"
      :update="updateScene"
      :get-form-data="getFormData"
      :get-search-data="getSearchData"
    />

  </div>
</template>

<script>

import CommonView from '@/components/commonView/index'
import { getSceneList, addScene, deleteScene, updateScene } from '@/api/scene'

export default {
  name: 'SceneList',
  components: { 'common-view': CommonView },
  data() {
    return {
      getSceneList,
      addScene,
      updateScene,
      deleteScene,
      tableData: [],
      tableProp: [
        {
          prop: 'sceneName',
          label: '名称',
          width: 100
        }, {
          prop: 'sceneImage',
          label: '图片',
          width: 400
        },
        {
          prop: 'sceneDesc',
          label: '描述'
        }
      ],
      formRules: {
        sceneName: [
          { required: true, message: '请输入名称', trigger: 'change' }
        ]
      }
    }
  },
  mounted() {
    // 数据初始化
  },
  methods: {
    // 新增、编辑表单转换
    getFormData(formData, handle, id) {
      console.log('转换前', formData)
      const { sceneName, sceneDesc, sceneImage } = formData
      const newFormData = { sceneName, sceneDesc, sceneImage }
      if (handle === 'edit') {
        newFormData['id'] = id
      }
      return newFormData
    },
    // 查询条件转换
    getSearchData(formData) {
      const { sceneName } = formData
      return {
        sceneName
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
}
</style>
